Skip to content

Conversation

@paulormart
Copy link
Contributor

Panic when running example below. I could use try_fetch for similar cases, but I think is better to propagate an error under fetch?

storage_client_at.rs:327:10:
called `Option::unwrap()` on a `None` value
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
#![allow(missing_docs)]
use sp_core::H256;
use std::str::FromStr;
use subxt::{OnlineClient, PolkadotConfig, utils::AccountId32};
use subxt_signer::sr25519::dev;

// Generate an interface that we can use from the node's metadata.
#[subxt::subxt(
    runtime_metadata_path = "../artifacts/latest/asset_hub_polkadot_metadata_small.scale"
)]
pub mod polkadot {}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create a new API client, configured to talk to Polkadot nodes.
    let api =
        OnlineClient::<PolkadotConfig>::from_url("wss://asset-hub-polkadot.rpc.turboflakes.io")
            .await?;
    let account: AccountId32 = dev::alice().public_key().into();

    // Build a storage query to access account information.
    let storage_query = polkadot::storage().system().account();

    // Use that query to access a storage entry, fetch a result and decode the value.
    // The static address knows that fetching requires a tuple of one value, an
    // AccountId32.
    let client_at = api.storage().at_latest().await?;
    let account_info = client_at
        .entry(storage_query)?
        .fetch((account.clone(),))
        .await?
        .decode()?;

    // The static address that we got from the subxt macro knows the expected input
    // and return types, so it is decoded into a static type for us.
    println!("Alice: {account_info:?}");


    // Fetch staking ledger from an account
    let addr = polkadot::storage().staking().ledger();

    let api_at = api.storage().at_latest().await?;
    let result = api_at
        .entry(addr)?
        .fetch((account.clone(),))
        .await?
        .decode()?;

    println!("ledger: {result:?}");

    Ok(())
}

@paulormart paulormart requested a review from a team as a code owner January 21, 2026 11:51
@jsdw
Copy link
Collaborator

jsdw commented Jan 21, 2026

Thank you for spotting this!

In fact, this has been fixed in the rather big incoming PR which I'd like to get merged here:

#2131

(see https://github.com/paritytech/subxt/blob/jsdw-subxt-new/subxt/src/storage/storage_entry.rs#L177)

So I'll close this as I owuld like to get that merged soon and this would be a merge conflict :)

@jsdw jsdw closed this Jan 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants